package com.blog.blogservice.api.controller.v1;

import com.blog.blogservice.app.service.CategoryService;
import com.blog.blogservice.domain.entity.BaseResponse;
import com.blog.blogservice.domain.entity.Category;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 类别表(Category)表控制层
 *
 * @author guanglin.ma
 * @since 2024-03-02 23:25:31
 */

@RestController("categoryController.v1")
@RequestMapping("/v1/categorys")
@RequiresPermissions("admin")
public class CategoryController {


    @Autowired
    private CategoryService categoryService;

    //    类别表列表
    @GetMapping("/list/categorys")
    public BaseResponse<List<Category>> list(Category category) {
        List<Category> list = categoryService.selectList(category);
        return new BaseResponse("20000", list);
    }

    //    类别表明细
    @GetMapping("/{categoryId}")
    public ResponseEntity<Category> detail(@PathVariable Long categoryId) {

        return null;
    }

    //    创建或更新类别表
    @PostMapping("/new/categorys")
    public BaseResponse<List<Category>> save(@RequestBody List<Category> categorys) {
        List<Category> resultList = this.categoryService.saveData(categorys);
        return new BaseResponse("20000", resultList);
    }

    //    删除类别表
    @DeleteMapping("/abandon/categorys")
    public BaseResponse<Void> remove(@RequestBody List<Category> categorys) {
        this.categoryService.deleteData(categorys);
        return BaseResponse.ok();
    }

}

